package com.cl.unipay4j.wx;

import com.cl.unipay4j.core.IPayConfig;
import com.cl.unipay4j.core.IPayFactory;
import com.cl.unipay4j.core.pay.INotify;
import com.cl.unipay4j.core.pay.IPayment;
import com.cl.unipay4j.core.pay.IQuery;
import com.cl.unipay4j.core.pay.IRefund;
import com.cl.unipay4j.core.transfer.ITransfer;
import com.cl.unipay4j.core.transfer.ITransferQuery;
import com.cl.unipay4j.wx.pay.*;
import com.cl.unipay4j.wx.transfer.WxPayTransfer;
import com.cl.unipay4j.wx.transfer.WxPayTransferQuery;

/**
 * 微信支付工厂类
 *
 * @author siashan
 * @since v1.0.1
 **/
public class WxPayFactory implements IPayFactory {

    /**
     * 根据支付类型获得支付类
     *
     * @param tradeType   交易类型
     * @return 支付类
     */
    @Override
    public IPayment getPayment(String tradeType) {
        IPayment payment = null;
        switch (Enum.valueOf(WxTradeTypeEnum.class, tradeType)) {
            case H5:
                payment = new WxPayH5();
                break;
            case APP:
                payment = new WxPayApp();
                break;
            case XCX:
                payment = new WxPayXCX();
                break;
            case JSAPI:
                payment = new WxPayJSAPI();
                break;
            case NATIVE:
                payment = new WxPayNative();
                break;
            case MICROPAY:
                payment = new WxPayMICRO();
                break;
            default:
                break;
        }
        return payment;
    }

    /**
     * 根据支付类型获得支付类
     *
     * @param tradeType  交易类型
     * @param payConfig  支付配置
     * @since v1.0.1
     * @return com.cl.unipay4j.core.pay.IPayment
     */
    @Override
    public IPayment getPayment(String tradeType, IPayConfig payConfig) {
        IPayment payment = null;
        switch (Enum.valueOf(WxTradeTypeEnum.class, tradeType)) {
            case H5:
                payment = new WxPayH5(payConfig);
                break;
            case APP:
                payment = new WxPayApp(payConfig);
                break;
            case XCX:
                payment = new WxPayXCX(payConfig);
                break;
            case JSAPI:
                payment = new WxPayJSAPI(payConfig);
                break;
            case NATIVE:
                payment = new WxPayNative(payConfig);
                break;
            case MICROPAY:
                payment = new WxPayMICRO(payConfig);
                break;
            default:
                break;
        }
        return payment;
    }

    /**
     * 获取支付查询类
     *
     * @return 支付查询类
     */
    @Override
    public IQuery getQuery() {
        return new WxPayQuery();
    }

    /**
     * 获取查询类
     *
     * @param payConfig  支付配置
     * @return 支付查询类
     */
    @Override
    public IQuery getQuery(IPayConfig payConfig) {
        return new WxPayQuery(payConfig);
    }

    /**
     * 获取支付回调通知类
     *
     * @return 支付回调通知类
     */
    @Override
    public INotify getNotify() {
        return new WxPayNotify();
    }

    /**
     * 获取异步通知类
     *
     * @param payConfig  支付配置信息
     * @return 支付回调类
     */
    @Override
    public INotify getNotify(IPayConfig payConfig) {
        return new WxPayNotify(payConfig);
    }

    /**
     * 获取转账类
     *
     * @return 支付转账类
     */
    @Override
    public ITransfer getTransfer() {
        return new WxPayTransfer();
    }

    /**
     * 获取转账类
     *
     * @param payConfig  支付配置
     * @return 支付转账类
     */
    @Override
    public ITransfer getTransfer(IPayConfig payConfig) {
        return new WxPayTransfer(payConfig);
    }


    /**
     * 获取转账查询类
     *
     * @return 转账查询类
     */
    @Override
    public ITransferQuery getTransferQuery() {
        return new WxPayTransferQuery();
    }

    /**
     * 获取转账查询类
     *
     * @param payConfig  支付配置
     * @return 转账查询类
     */
    @Override
    public ITransferQuery getTransferQuery(IPayConfig payConfig) {
        return new WxPayTransferQuery(payConfig);
    }

    /**
     * 获取退款类
     *
     * @return 退款类
     */
    @Override
    public IRefund getRefund() {
        return new WxPayRefund();
    }

    /**
     * 获取退款类
     *
     * @param payConfig  支付配置
     * @return 退款类
     */
    @Override
    public IRefund getRefund(IPayConfig payConfig) {
        return new WxPayRefund(payConfig);
    }

}
